/**
 * @file QDSewer.cpp
 * @author redfrogotr
 * @brief Quick and Dirty Sewer
 * @version 0.1
 * @date 2022-04-12
 */
#include <iostream>
using namespace std;

class Trait {
public:
    virtual int transform(int srcNum) = 0;
    virtual ~Trait() {}
};

class Increasing: public Trait {
public:
    int transform(int srcNum);
};

class Reversing: public Trait {
public:
    int transform(int srcNum);
};

class Doubling: public Trait {
public:
    int transform(int srcNum);
};

int Increasing::transform(int srcNum) {
    return srcNum + 1;
}

int Reversing::transform(int srcNum) {
    return -srcNum;
}

int Doubling::transform(int srcNum) {
    return srcNum * 2;
}

class QDSewer {
private:
    int queue[5];
    int putIdx, getIdx;
    Trait* traits[3];
    int traitsSize;
public:
    explicit QDSewer();
    ~QDSewer();
    void with(Trait* trait);
    void put(int num);
    int get();
};

QDSewer::QDSewer() : putIdx(0), getIdx(0), traitsSize(0) {}

QDSewer::~QDSewer() {
    for (int i = 0; i < traitsSize; i++) {
        delete traits[i];
    }
}

void QDSewer::with(Trait* trait) {
    traits[traitsSize++] = trait;
}

void QDSewer::put(int num) {
    queue[putIdx++] = num;
}

int QDSewer::get() {
    int num = queue[getIdx++];
    for (int i = 0; i < traitsSize; i++) {
        num = traits[i]->transform(num);
    }
    return num;
}


int main(int argc, char const *argv[])
{
    QDSewer sewer;
    int traitsNum;

    cin >> traitsNum;
    for (int i = 0; i < traitsNum; i++) {
        int traitKey;
        cin >> traitKey;
        if (traitKey == 0) {
            sewer.with(new Increasing());
        } else if (traitKey == 1) {
            sewer.with(new Reversing());
        } else {
            sewer.with(new Doubling());
        }
    }
    // put
    for (int i = 0; i < 5; i++) {
        int num;
        cin >> num;
        sewer.put(num);
    }
    // pop
    for (int i = 0; i < 5; i++) {
        cout << sewer.get() << " ";
    }

    return 0;
}
